package cn.ad.server.web.init;

import cn.ad.server.web.spring.service.actions.context.IPContext;

import java.io.IOException;

/**
 * IP 地址库初始化类
 * @author dongbin.yu
 * @from 2016-05-30
 * @since V1.0
 */
public class IPDetailIniti implements IAdserverInitialization {
	
	/**
	 * ip 地址库配置文件地址
	 */
	private String ipDetailConfig;
	
	/**
	 * 缺省的配置文件路径
	 */
	private static final String DEFAULT_IPCONFIG_PATH = "/IPDetails.txt";
	
    /**
	 * @return the ipDetailConfig
	 */
	public String getIpDetailConfig() {
		return ipDetailConfig;
	}

	/**
	 * @param ipDetailConfig the ipDetailConfig to set
	 */
	public void setIpDetailConfig(String ipDetailConfig) {
		this.ipDetailConfig = ipDetailConfig;
	}

	/* (non-Javadoc)
	 * @see cn.falconnect.adserver.adapter.IAdserverInitialization#init()
	 */
	@Override
	public void init() throws AdserverInitException {
		 try {
			 ipDetailConfig = ipDetailConfig == null ? DEFAULT_IPCONFIG_PATH : ipDetailConfig;
			IPContext.instance().init(ipDetailConfig);
		} catch (IOException e) {
			throw new AdserverInitException(e.getMessage(), e);
		} catch(NullPointerException e){
			throw new AdserverInitException("配置ip地址资源文件出现异常.file:[" + ipDetailConfig + "]", e);
		}
	}
}
